/**
* @file			main.c
* @author  		Jayasingam Adhuran
* @date    		December 5, 2014
* @brief   		Template code for main program.
*/

/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include "LCD.h"
#include "Buzzer.h"
#include "LED.h"
#include "PIR.h"
#include "stm32f0xx_exti.h"
#include "stm32f0xx_misc.h"
#include "arduino.h"
#include "keypad.h"
#include "keypadwrite.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

// /**
//* @brief	The configure_interrupt() function will only run once, after each powerup or reset of the board. Use it to initialize the interrupt.
//* @param	None
//* @retval	None
//*/

//void configure_interrupt(){
//NVIC_InitTypeDef nvic_init_struct;
//EXTI_InitTypeDef exti_init_struct;
//	// Configure NVIC with USART2 as interrupt source
//	nvic_init_struct.NVIC_IRQChannel = USART2_IRQn;
//	nvic_init_struct.NVIC_IRQChannelCmd = ENABLE;
//	nvic_init_struct.NVIC_IRQChannelPriority = 0;
//	NVIC_Init(& nvic_init_struct);
//	
//	///* Configure Exti *********************************/
//exti_init_stuct.EXTI_Line=EXTI_Line10;
//exti_init_stuct.EXTI_Mode=EXTI_Mode_Interrupt;
//exti_init_stuct.EXTI_Trigger=EXTI_Trigger_Rising;
//exti_init_stuct.EXTI_LineCmd=ENABLE;	
//EXTI_Init(&exti_init_struct);
//EXTI_GenerateSWInterrupt(EXTI_Line10);

//}

////Interrupt handler

//void EXTI4_15_IRQHandler(void)
//    {
//			
//			
//			
//		}

 /**
* @brief	The setup() function will only run once, after each powerup or reset of the board. Use it to initialize variables.
* @param	None
* @retval	None
*/

int password;

void setup()
{
	SysTick_Config(SystemCoreClock/1000);
	LCD_Init();
	initgpio();
}

void set_password(){
	
	Enter_new_password();
	while(!keypad_status());
	password = read_code();
 
}

int main(){
int code = 4123;	
setup();	

while(1){
	
//while(!getPIRstatus());
LCD_ALARM_ON();
while(!keypad_status());
LCD_write(read_code());	
if (read_code()==code){
	analogWrite(5, 0);

}
	
}
return 1;
}